package zy;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ThreadTest {
	static ArrayList<String> list1 = new ArrayList<>();
	static boolean flag=false;
	static int count=1;
	 
	public static void main(String[] args) throws Exception{
		ExecutorService pool = Executors.newCachedThreadPool();
		ArrayList<Integer> list=new ArrayList<>();
		Collections.addAll(list, 10,5,20,50,100,200,550,800,2,80,300,1000);
//第一题   抽奖
	/*	MyCallable c1 = new MyCallable(list);
		MyCallable c2 = new MyCallable(list);
		Future<Integer> value1 = pool.submit(c1);
		Future<Integer> value2 = pool.submit(c2);
		 if(value2.get()==null){
			 System.out.println("抽奖箱1产生了最大值为："+value1.get());
		 }else if(value1.get()==null){
			 System.out.println("抽奖箱2产生了最大值为："+value2.get());
		 }else if(value1.get()>value2.get()){
			 System.out.println("抽奖箱1产生了最大值为："+value1.get());
		 }else if(value2.get()>value1.get()){		
			 System.out.println("抽奖箱2产生了最大值为："+value2.get());
		 }*/
//第二题  生产5个 消费5个
	/*	Desk d = new Desk(0);
		Producer c = new Producer(d);
		Consumer c1 = new Consumer(d);
		pool.submit(c);
		pool.submit(c1);
		pool.shutdown();*/
		
//第三题  子进程先执行三次，主进程再执行五次    主线程用Thread提交		
	/*	final Object lock = new Object();
		MyRunnable t = new MyRunnable(lock);
		pool.submit(t);
		new Thread(new Runnable() {
			public void run() {
				Thread.currentThread().setName("主线程");
				synchronized (lock) {
					while(count<4){
						if(flag){
							for(int i=1;i<=5;i++){
								 System.out.println(Thread.currentThread().getName()+"在执行"+i);
							 }
							flag=false;
							count++;
						    lock.notifyAll();
						}else{
							try {
								lock.wait();
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
						}
					}
				}

			}
		}).start();
		pool.shutdown();*/
		 
//第四题 编写一个可以从 1 到 n 输出代表这个数字的字符串的程序

	/*	 System.out.println("请输入一个整数：");
		 Scanner sc = new Scanner(System.in);
		 int value = sc.nextInt();
		 FizzBuzz fb = new FizzBuzz(value);
		 PrintFizz pf = new PrintFizz(fb);
		 PrintBuzz pb = new PrintBuzz(fb);
		 PrintFizzBuzz pfb = new PrintFizzBuzz(fb);
		 PrintNumber pn = new PrintNumber(fb);
		 pool.submit(pf);
		 pool.submit(pb);
		 pool.submit(pfb);
		 pool.submit(pn);
		 pool.shutdown();*/
		 
//第5题	 写两个线程，一个线程打印1~ 52，另一个线程打印A~Z，打印顺序是12A34B…5152Z
		 
	/*	MyThread mt = new MyThread();
		Digit d = new Digit(mt);
		Letter l = new Letter(mt);
		pool.submit(d);
		pool.submit(l);
		pool.shutdown();*/

//第6题	 使用多线程实现多个文件同步复制功能，并在控制台显示复制的进度，进度以百分比表示。例如：把文件A复制到E盘某文件夹下，在控制台上显示“XXX文件已复制10%”，“XXX文件已复制20%”……“XXX文件已复制100%”，“XXX复制完成！”
		 
	/*	 CopyThread c1 = new CopyThread("D:\\aaa\\a.txt", "D:\\bbb\\b.txt");
		 CopyThread c2 = new CopyThread("D:\\aaa\\b.txt", "E:\\ccc\\c.txt");
		 pool.submit(c1);
		 pool.submit(c2);
		 pool.shutdown();*/

//	第7题	 设计4个线程，其中两个线程每次对j增加1，另外两个线程对j每次减少1。考虑到线程的安全性写出程序。
		 
	/*	Change c = new Change(0);
		Minus m1 = new Minus(c);
		Minus m2 = new Minus(c);
		Add a1 = new Add(c);
		Add a2 = new Add(c);
		pool.submit(m1);
		pool.submit(m2);
		pool.submit(a1);
		pool.submit(a2);
		pool.shutdown();*/
		 
//第8题 现有函数 printNumber 可以用一个整数参数调用，并输出该整数到控制台。
		 
		 System.out.print("请输入一个整数：");
		 Scanner sc = new Scanner(System.in);
		 int n = sc.nextInt();
		 ZeroEvenOdd zeo = new ZeroEvenOdd(n);
		 Zero z = new Zero(zeo);
		 Even e = new Even(zeo);
		 Odd o = new Odd(zeo);
		 pool.submit(z);
		 pool.submit(e);
		 pool.submit(o);
		 pool.shutdown();
	}
}
